package com.slipper.system.codeless.service;

import com.slipper.system.codeless.bo.ViewBO;
import com.slipper.system.codeless.bo.ViewHistoryBO;
import com.slipper.system.codeless.dao.ViewHistoryDao;
import com.slipper.core.transaction.ReadTransactional;
import com.slipper.core.transaction.WriteTransactional;
import com.slipper.util.BeanUtil;
import com.slipper.util.Tool;
import com.slipper.util.UUID;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@ReadTransactional
public class ViewHistoryService {
    @Resource
    private ViewHistoryDao viewHistoryDao;
    
    public ViewHistoryBO queryBy(String id) {
        return viewHistoryDao.queryBy(id);
    }
    
    public List<ViewHistoryBO> queryList(ViewHistoryBO bo) {
        return viewHistoryDao.queryList(bo);
    }

    @WriteTransactional
    public int save(ViewBO bo) {
        if (Tool.isBlank(bo.getSqlText())) return 0;

        ViewHistoryBO history = BeanUtil.copy(bo, ViewHistoryBO.class);
        history.setId(UUID.getUUID());
        history.setViewId(bo.getId());
        history.setCreateTime(System.currentTimeMillis());
        return viewHistoryDao.insert(history);
    }
}
